In this article, we will discuss different ways of running the Spring Boot application.
Spring boot offers several ways of running Spring boot applications.
This tutorial is explained in the below Youtube Video. Subscribe to my youtube channel to learn more about Spring boot at
You can run a Spring Boot application from your IDE as a simple Java application (Application.java or Main class).
If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using java -jar. For example, change the directory to the current project directory and run following command in cmd.
$ java -jar target/myapplication-0.0.1-SNAPSHOT.jar
It is also possible to run a packaged application with remote debugging support enabled. Doing so lets you attach a debugger to your packaged application, as shown in the following example:
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myapplication-0.0.1-SNAPSHOT.jar
The Spring Boot Maven plugin includes a run goal that can be used to quickly compile and run your application. Applications run in an exploded form, as they do in your IDE. The following example shows a typical Maven command to run a Spring Boot application:
$ mvn spring-boot:run
We can also use the MAVEN_OPTS operating system environment variable, as shown in the following example:
$ export MAVEN_OPTS=-Xmx1024m
We can also deploy Spring Boot web application WAR file to the external Tomcat servlet container. There are three steps we can follow to create a war file and deploy in an external Tomcat servlet container.
< packaging>war< /packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
There is a separate article to know more how to deploy Spring boot WAR file to external tomcat on
Boot Deploy WAR file to External Tomcat
The Spring Boot Gradle plugin also includes a bootRun task that can be used to run your application in an exploded form. The bootRun task is added whenever you apply the org.springframework.boot and java plugins and is shown in the following example:
$ gradle bootRun
You might also want to use the JAVA_OPTS operating system environment variable, as shown in the following example:
$ export JAVA_OPTS=-Xmx1024m
Read 25+ Spring Boot Articles with Source Code on GitHub -Spring Boot Tutorial